/* Global  */
var x1 = 0 , x2 = 0 , times = 0; // pop img x1 x2

var startX = 24 , endX = 0;

var childrenNum = 0;

var childrenWidth = 0;

var currentChildrenWidth = 0;


function popImgList(obj){

	var parent = obj;

	var parentWidth = 0;

	parent.children("li").eq(0).addClass("current");

	parent.children("li").each(function(){

		childrenNum++;
		
		childrneWidth = $(this).width() + 5;

		console.log(childrneWidth);

		parentWidth += $(this).width() + 5;

	});

	parent.css("width", parentWidth + "px");

}

function popImgListTouch(obj){

	obj.on("touchstart",function(event){

		var touchX = event.originalEvent.touches[0];

		x1 = touchX.pageX;

	})

	obj.on("touchmove",function(event){

		var touchX = event.originalEvent.touches[0];

		x2 = touchX.pageX;

	})

	obj.on("touchend",function(){

		var _left = parseInt(obj.css("left").split("p")[0]);

		currentChildrenWidth = obj.children(".current").width() - 19;

		var currentIndex = obj.children(".current").index();

		if( x2 - x1 > 0 ){

			times = ( times == 0 ) ? 0 : -1;

		} else if ( x2 - x1 < 0 ){

			times = ( times == childrenNum ) ? 0 : 1;

		}

		if( currentIndex == 0 && times < 0 ){

			times = 0;

		}else if( currentIndex == childrenNum && times > 0 ){

			times = 0;

		}

		obj.children("li").eq(currentIndex + times).addClass("current").siblings("li").removeClass("current");

		obj.stop().animate({'left': _left - times * currentChildrenWidth + "px"});

	})

}